package cn.gson.work.model.service;

import cn.gson.work.model.mapper.PositionsMapper;
import cn.gson.work.model.pojos.Dept;
import cn.gson.work.model.pojos.Position;
import cn.gson.work.model.pojos.User;
import cn.gson.work.model.vo.PositionQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class PositionService {
    @Autowired
    PositionsMapper posm;

    /**
     * 分页查询职位信息
     * @param query
     * @return
     */
    public Map<String,Object> getPosition(PositionQuery query){
        Map<String,Object> map = new HashMap<String,Object>();
        PageHelper.startPage(query.getCurpage(),query.getPagesize());
        List<Position> list = posm.getPosition(query);
        PageInfo<Position> info = new PageInfo<>(list);
        map.put("list",list);
        map.put("total",info.getTotal());
        return map;
    }

    /**
     * 新增职位信息
     * @param position
     */
    public void addPosition(Position position){
        posm.addPosition(position);
    }

    /**
     * 修改职位信息
     * @param position
     */
    public void editPosition(Position position){
        posm.editPosition(position);
    }
}
